github.com/RedHatInsights/insights-content-service@v1.0.0/groups/groups_test.go (about)

     1  /*
     2  Copyright © 2020 Red Hat, Inc.
     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 groups_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/RedHatInsights/insights-content-service/groups"
    23  )
    24  
    25  // TestParseGroupConfigFileNonExistingFile check whether non existing file is detected properly
    26  func TestParseGroupConfigFileNonExistingFile(t *testing.T) {
    27  	// the following file does not exist
    28  	_, err := groups.ParseGroupConfigFile("this does not exist")
    29  	if err == nil {
    30  		t.Log(err)
    31  		t.Fatal("Error should be returned for non existing file")
    32  	}
    33  }
    34  
    35  // TestParseGroupConfigFileNonExistingFile check whether non YAML file is detected properly
    36  func TestParseGroupConfigFileNotYamlFile(t *testing.T) {
    37  	// the following file does exist, but it is not proper YAML file
    38  	_, err := groups.ParseGroupConfigFile("../LICENSE")
    39  	if err == nil {
    40  		t.Log(err)
    41  		t.Fatal("Error should be returned for improper file format")
    42  	}
    43  }
    44  
    45  // TestParseGroupConfigFileProperYamlFile is basic test for checking whether group configuration file can be read properly
    46  func TestParseGroupConfigFileProperYamlFile(t *testing.T) {
    47  	// the following file does exist, but it is not proper YAML file
    48  	_, err := groups.ParseGroupConfigFile("../groups_config.yaml")
    49  	if err != nil {
    50  		t.Log(err)
    51  		t.Fatal("Error should not be returned for existing and proper file")
    52  	}
    53  	// TODO: more checks will need test_config.yaml
    54  }