github.com/joelanford/operator-sdk@v0.8.2/internal/pkg/scaffold/olm-catalog/config_test.go (about)

     1  // Copyright 2018 The Operator-SDK Authors
     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 catalog
    16  
    17  import (
    18  	"path/filepath"
    19  	"reflect"
    20  	"testing"
    21  
    22  	"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
    23  )
    24  
    25  func TestConfig(t *testing.T) {
    26  	crdsDir := filepath.Join(testDataDir, scaffold.CRDsDir)
    27  
    28  	cfg := &CSVConfig{
    29  		CRDCRPaths: []string{crdsDir},
    30  	}
    31  	if err := cfg.setFields(); err != nil {
    32  		t.Errorf("Set fields crd-cr paths dir only: (%v)", err)
    33  	}
    34  	if len(cfg.CRDCRPaths) != 3 {
    35  		t.Errorf("Wanted 3 crd/cr files, got: %v", cfg.CRDCRPaths)
    36  	}
    37  
    38  	cfg = &CSVConfig{
    39  		CRDCRPaths: []string{crdsDir, filepath.Join(crdsDir, "app_v1alpha1_app_crd.yaml")},
    40  	}
    41  	if err := cfg.setFields(); err != nil {
    42  		t.Errorf("Set fields crd-cr paths dir file mix: (%v)", err)
    43  	}
    44  	want := []string{
    45  		filepath.Join(crdsDir, "app_v1alpha1_app_cr.yaml"),
    46  		filepath.Join(crdsDir, "app_v1alpha1_app_crd.yaml"),
    47  		filepath.Join(crdsDir, "app_v1alpha2_app_crd.yaml"),
    48  	}
    49  	if !reflect.DeepEqual(want, cfg.CRDCRPaths) {
    50  		t.Errorf("Wanted crd/cr files %v, got %v", want, cfg.CRDCRPaths)
    51  	}
    52  }