Skip to content

Commit

Permalink
enhance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tch1b0 committed Sep 18, 2023
1 parent 764128a commit d10f1b7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/paths/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ func TestPathsCreation(t *testing.T) {
require.Equal(t, "/test/addons/x", p2.Root)
require.Equal(t, cln("/test/addons"), p2.Addons)
require.Equal(t, cln("/test/addons/x/ppm.json"), p2.ConfigFile)

p3, err := CreatePathsFromCwd()
require.Nil(t, err)
require.NotNil(t, p3.Addons)
require.NotNil(t, p3.ConfigFile)
require.NotNil(t, p3.Root)
}
File renamed without changes.
78 changes: 78 additions & 0 deletions internal/pm/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package pm

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

const ppmConfigStr = `
{
"plugin": false,
"dependencies": [
{
"identifier": "additional-audio-players",
"version": null,
"url": "https://github.com/Glow-Project/additional-audio-players",
"type": "GITHUB_ASSET"
}
],
"sub-dependencies": []
}
`

func withTempFile(content []byte, fn func(path *os.File)) {
f, err := os.CreateTemp("", "tmpfile-")
if err != nil {
panic(err)
}

defer f.Close()
defer os.Remove(f.Name())

if _, err := f.Write(content); err != nil {
panic(err)
}

fn(f)
}

func withTempDir(fn func(path string)) {
tmpDir := os.TempDir()

dir, err := os.MkdirTemp(tmpDir, "*")
if err != nil {
panic(err)
}

defer os.RemoveAll(dir)

fn(dir)
}

func TestConfigCreation(t *testing.T) {
withTempDir((func(path string) {
ppm, err := CreateConfig(path)
assert.Nil(t, err)
assert.False(t, ppm.IsPlugin)

assert.Equal(t, len(ppm.Dependencies), 0)
assert.Equal(t, len(ppm.SubDependencies), 0)
}))

withTempFile([]byte(ppmConfigStr), func(v *os.File) {
ppm, err := ParseConfig(v.Name())
assert.Nil(t, err)
assert.False(t, ppm.IsPlugin)

assert.Equal(t, len(ppm.Dependencies), 1)
assert.Equal(t, len(ppm.SubDependencies), 0)

dep := ppm.Dependencies[0]
assert.Equal(t, dep.Identifier, "additional-audio-players")
assert.Nil(t, dep.Version)
assert.Equal(t, dep.Url, "https://github.com/Glow-Project/additional-audio-players")
assert.Equal(t, dep.Type, "GITHUB_ASSET")
})
}

0 comments on commit d10f1b7

Please sign in to comment.