Skip to content

Commit

Permalink
cmd/otk-resolve-ostree-commit: test the mock resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k authored and mvo5 committed Sep 24, 2024
1 parent 890900a commit 50151b3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/otk-resolve-ostree-commit/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ package main
var (
Run = run
)

func MockEnvLookup() (restore func()) {
saved := osLookupEnv
osLookupEnv = func(key string) (string, bool) {
if key == "OTK_UNDER_TEST" {
return "1", true
}
return "", false
}
return func() {
osLookupEnv = saved
}
}
32 changes: 32 additions & 0 deletions cmd/otk-resolve-ostree-commit/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,35 @@ func TestResolverErrors(t *testing.T) {
})
}
}

func TestMockResolve(t *testing.T) {
restore := resolver.MockEnvLookup()
defer restore()

assert := assert.New(t)

inputReq := `
{
"tree": {
"ref": "otk/ostree/test",
"url": "https://ostree.example.org/repo"
}
}
`
expOutput := `{
"tree": {
"const": {
"ref": "otk/ostree/test",
"url": "https://ostree.example.org/repo",
"checksum": "5c1c0655481926623eca85109dd4017c8dba320ea1473c42b43005db6d900a60"
}
}
}
`
input := bytes.NewBuffer([]byte(inputReq))
output := &bytes.Buffer{}

assert.NoError(resolver.Run(input, output))

assert.Equal(expOutput, output.String())
}

0 comments on commit 50151b3

Please sign in to comment.