github.com/kubeshop/testkube@v1.17.23/contrib/executor/k6/pkg/k6detector/k6.go (about)

     1  package k6detector
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  
     7  	apiClient "github.com/kubeshop/testkube/pkg/api/v1/client"
     8  )
     9  
    10  // Detector is detector adapter for K6 test
    11  type Detector struct{}
    12  
    13  const (
    14  	// Type is test type
    15  	Type = "k6/script"
    16  )
    17  
    18  // Is detects based on upsert test options what kind of test it is
    19  func (d Detector) Is(options apiClient.UpsertTestOptions) (name string, ok bool) {
    20  	if options.Content == nil {
    21  		return
    22  	}
    23  
    24  	if strings.Contains(options.Content.Data, "from 'k6") {
    25  		return d.GetType(), true
    26  	}
    27  
    28  	return
    29  }
    30  
    31  // IsWithPath detects based on upsert test options what kind of test it is
    32  func (d Detector) IsWithPath(path string, options apiClient.UpsertTestOptions) (name string, ok bool) {
    33  	name, ok = d.Is(options)
    34  	ext := filepath.Ext(path)
    35  	ok = ok && (ext == ".js")
    36  	return
    37  }
    38  
    39  // GetType returns test type
    40  func (d Detector) GetType() string {
    41  	return Type
    42  }