github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/circle/internal/orbs/golang/golang_test.go (about)

     1  // Copyright 2022 Harness, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package golang
    16  
    17  import (
    18  	"testing"
    19  
    20  	circle "github.com/drone/go-convert/convert/circle/yaml"
    21  	harness "github.com/drone/spec/dist/go"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  )
    25  
    26  func TestConvertTest(t *testing.T) {
    27  	in := &circle.Custom{
    28  		Params: map[string]interface{}{},
    29  	}
    30  
    31  	got := Convert("test", in)
    32  	want := &harness.Step{
    33  		Name: "go_test",
    34  		Type: "script",
    35  		Spec: &harness.StepExec{
    36  			Run: "go test -cover ./...",
    37  		},
    38  	}
    39  
    40  	if diff := cmp.Diff(got, want); diff != "" {
    41  		t.Errorf("Unexpected orb conversion")
    42  		t.Log(diff)
    43  	}
    44  }
    45  
    46  func TestConvertTestParams(t *testing.T) {
    47  	in := &circle.Custom{
    48  		Params: map[string]interface{}{
    49  			"verbose":  true,
    50  			"race":     true,
    51  			"short":    true,
    52  			"parallel": 5,
    53  		},
    54  	}
    55  
    56  	got := Convert("test", in)
    57  	want := &harness.Step{
    58  		Name: "go_test",
    59  		Type: "script",
    60  		Spec: &harness.StepExec{
    61  			Run: "go test -cover -parallel 5 -v -race -short ./...",
    62  		},
    63  	}
    64  
    65  	if diff := cmp.Diff(got, want); diff != "" {
    66  		t.Errorf("Unexpected orb conversion")
    67  		t.Log(diff)
    68  	}
    69  }
    70  
    71  func TestConvertInstall(t *testing.T) {
    72  	in := &circle.Custom{
    73  		Params: map[string]interface{}{},
    74  	}
    75  
    76  	got := Convert("install", in)
    77  	want := &harness.Step{
    78  		Name: "go_install",
    79  		Type: "script",
    80  		Spec: &harness.StepExec{
    81  			Run: "go install ./...",
    82  		},
    83  	}
    84  
    85  	if diff := cmp.Diff(got, want); diff != "" {
    86  		t.Errorf("Unexpected orb conversion")
    87  		t.Log(diff)
    88  	}
    89  }