github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/inspect/tests/list.go (about)

     1  /*
     2  Copyright 2021 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package inspect
    18  
    19  import (
    20  	"context"
    21  	"io"
    22  
    23  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
    24  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect"
    25  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
    26  )
    27  
    28  type testList struct {
    29  	Tests []interface{} `json:"tests"`
    30  }
    31  
    32  // CustomTest entries are handled by CustomTest struct, there is no StructureTest so structureTestEntry is required
    33  type structureTestEntry struct {
    34  	TestType          string   `json:"testType"`
    35  	StructureTest     string   `json:"structureTest"`
    36  	StructureTestArgs []string `json:"structureTestArgs"`
    37  }
    38  
    39  type customTestEntry struct {
    40  	TestType string `json:"testType"`
    41  	latest.CustomTest
    42  }
    43  
    44  func PrintTestsList(ctx context.Context, out io.Writer, opts inspect.Options) error {
    45  	formatter := inspect.OutputFormatter(out, opts.OutFormat)
    46  	cfgs, err := inspect.GetConfigSet(ctx, config.SkaffoldOptions{
    47  		ConfigurationFile:   opts.Filename,
    48  		ConfigurationFilter: opts.Modules,
    49  		RepoCacheDir:        opts.RepoCacheDir,
    50  		Profiles:            opts.Profiles,
    51  		PropagateProfiles:   opts.PropagateProfiles,
    52  	})
    53  	if err != nil {
    54  		formatter.WriteErr(err)
    55  		return err
    56  	}
    57  
    58  	// TODO(aaron-prindle) add a field 'testType' to both objects
    59  	l := &testList{Tests: []interface{}{}}
    60  	for _, c := range cfgs {
    61  		for _, t := range c.Test {
    62  			for _, ct := range t.CustomTests {
    63  				l.Tests = append(l.Tests, customTestEntry{"custom-test", ct})
    64  			}
    65  			for _, st := range t.StructureTests {
    66  				l.Tests = append(l.Tests, structureTestEntry{"structure-test", st, t.StructureTestArgs})
    67  			}
    68  		}
    69  	}
    70  	return formatter.Write(l)
    71  }