Skip to content

Commit

Permalink
rename _script to _test part2
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Feb 10, 2022
1 parent 7a6f0f6 commit c7575f1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/scripts/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func newContentFromFlags(cmd *cobra.Command) (content *testkube.TestContent, err
// detect content type (git-file need to be everrided manually as we don't)
// TODO handle git-file somehow
if gitUri != "" && scriptContentType == "" {
scriptContentType = string(testkube.ScriptContentTypeGitDir)
scriptContentType = string(testkube.TestContentTypeGitDir)
}

if uri != "" && scriptContentType == "" {
scriptContentType = string(testkube.ScriptContentTypeFileURI)
scriptContentType = string(testkube.TestContentTypeFileURI)
}

if len(fileContent) > 0 {
scriptContentType = string(testkube.ScriptContentTypeString)
scriptContentType = string(testkube.TestContentTypeString)
}

var repository *testkube.Repository
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/client/direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestScriptsAPI(t *testing.T) {

// when
response, err := client.CreateScript(UpsertScriptOptions{
Content: testkube.NewStringScriptContent("{}"),
Content: testkube.NewStringTestContent("{}"),
Name: "t1",
Type_: "postman/collection",
})
Expand Down
26 changes: 13 additions & 13 deletions pkg/api/v1/testkube/model_test_content_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ package testkube

import "fmt"

type ScriptContentType string
type TestContentType string

const (
ScriptContentTypeString ScriptContentType = "string"
ScriptContentTypeFileURI ScriptContentType = "file-uri"
ScriptContentTypeGitFile ScriptContentType = "git-file"
ScriptContentTypeGitDir ScriptContentType = "git-dir"
TestContentTypeString TestContentType = "string"
TestContentTypeFileURI TestContentType = "file-uri"
TestContentTypeGitFile TestContentType = "git-file"
TestContentTypeGitDir TestContentType = "git-dir"
)

var ErrScriptContentTypeNotFile = fmt.Errorf("unsupported content type use one of: file-uri, git-file, string")
var ErrScriptContentTypeNotDir = fmt.Errorf("unsupported content type use one of: git-dir")
var ErrTestContentTypeNotFile = fmt.Errorf("unsupported content type use one of: file-uri, git-file, string")
var ErrTestContentTypeNotDir = fmt.Errorf("unsupported content type use one of: git-dir")

func NewStringScriptContent(str string) *TestContent {
func NewStringTestContent(str string) *TestContent {
return &TestContent{
Type_: string(ScriptContentTypeString),
Type_: string(TestContentTypeString),
Data: str,
}
}

// IsDir - for content fetched as dir
func (c *TestContent) IsDir() bool {
return ScriptContentType(c.Type_) == ScriptContentTypeGitDir
return TestContentType(c.Type_) == TestContentTypeGitDir

}

// IsFile - for content fetched as file
func (c *TestContent) IsFile() bool {
return ScriptContentType(c.Type_) == ScriptContentTypeGitFile ||
ScriptContentType(c.Type_) == ScriptContentTypeFileURI ||
ScriptContentType(c.Type_) == ScriptContentTypeString
return TestContentType(c.Type_) == TestContentTypeGitFile ||
TestContentType(c.Type_) == TestContentTypeFileURI ||
TestContentType(c.Type_) == TestContentTypeString
}
10 changes: 5 additions & 5 deletions pkg/executor/content/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func (f Fetcher) Fetch(content *testkube.TestContent) (path string, err error) {
if content == nil {
return "", fmt.Errorf("fetch - empty content, make sure script content has valid data structure and is not nil")
}
switch testkube.ScriptContentType(content.Type_) {
case testkube.ScriptContentTypeFileURI:
switch testkube.TestContentType(content.Type_) {
case testkube.TestContentTypeFileURI:
return f.FetchURI(content.Uri)
case testkube.ScriptContentTypeString:
case testkube.TestContentTypeString:
return f.FetchString(content.Data)
case testkube.ScriptContentTypeGitFile:
case testkube.TestContentTypeGitFile:
return f.FetchGitFile(content.Repository)
case testkube.ScriptContentTypeGitDir:
case testkube.TestContentTypeGitDir:
return f.FetchGitDir(content.Repository)
default:
return path, fmt.Errorf("unhandled content type: '%s'", content.Type_)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mapper/executions/sumary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func getExecutions() testkube.Executions {
"script1",
"execution1",
"test/test",
testkube.NewStringScriptContent(""),
testkube.NewStringTestContent(""),
*ex1,
map[string]string{"p": "v1"},
nil,
Expand All @@ -46,7 +46,7 @@ func getExecutions() testkube.Executions {
"script1",
"execution2",
"test/test",
testkube.NewStringScriptContent(""),
testkube.NewStringTestContent(""),
*ex2,
map[string]string{"p": "v2"},
nil,
Expand Down
6 changes: 3 additions & 3 deletions pkg/test/script/detector/curltest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCurlTestAdapter(t *testing.T) {
t.Run("Is return true when valid content", func(t *testing.T) {
detector := CurlTestAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(curlValidContent),
Content: testkube.NewStringTestContent(curlValidContent),
})

assert.True(t, is, "content should be of curl/test type")
Expand All @@ -29,7 +29,7 @@ func TestCurlTestAdapter(t *testing.T) {
t.Run("Is return false in case of invalid JSON content", func(t *testing.T) {
detector := CurlTestAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(curlInvalidContent),
Content: testkube.NewStringTestContent(curlInvalidContent),
})

assert.Empty(t, name)
Expand All @@ -40,7 +40,7 @@ func TestCurlTestAdapter(t *testing.T) {
t.Run("Is return false in case of content which is not JSON ", func(t *testing.T) {
detector := CurlTestAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(curlInvalidJSONContent),
Content: testkube.NewStringTestContent(curlInvalidJSONContent),
})

assert.Empty(t, name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/script/detector/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestDetector(t *testing.T) {
detector.Add(PostmanCollectionAdapter{})

name, found := detector.Detect(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(exampleValidContent),
Content: testkube.NewStringTestContent(exampleValidContent),
})

assert.True(t, found, "detector should find postman/collection")
Expand Down
6 changes: 3 additions & 3 deletions pkg/test/script/detector/postmancollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestPostmanCollectionAdapter(t *testing.T) {
t.Run("Is return true when valid content", func(t *testing.T) {
detector := PostmanCollectionAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(exampleValidContent),
Content: testkube.NewStringTestContent(exampleValidContent),
})

assert.Equal(t, "postman/collection", name)
Expand All @@ -29,7 +29,7 @@ func TestPostmanCollectionAdapter(t *testing.T) {
t.Run("Is return false in case of invalid JSON content", func(t *testing.T) {
detector := PostmanCollectionAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(exampleInvalidContent),
Content: testkube.NewStringTestContent(exampleInvalidContent),
})

assert.Empty(t, name)
Expand All @@ -40,7 +40,7 @@ func TestPostmanCollectionAdapter(t *testing.T) {
t.Run("Is return false in case of content which is not JSON ", func(t *testing.T) {
detector := PostmanCollectionAdapter{}
name, is := detector.Is(client.UpsertScriptOptions{
Content: testkube.NewStringScriptContent(exampleInvalidJSONContent),
Content: testkube.NewStringTestContent(exampleInvalidJSONContent),
})

assert.Empty(t, name)
Expand Down

0 comments on commit c7575f1

Please sign in to comment.