github.com/go-maxhub/gremlins@v1.0.1-0.20231227222204-b03a6a1e3e09/core/execution/execution_test.go (about)

     1  /*
     2   * Copyright 2022 The Gremlins 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 execution_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/go-maxhub/gremlins/core/execution"
    23  )
    24  
    25  func TestExitErr(t *testing.T) {
    26  	testCases := []struct {
    27  		name         string
    28  		wantExitMsg  string
    29  		errorType    execution.ErrorType
    30  		wantExitCode int
    31  	}{
    32  		{
    33  			name:         "efficacy-threshold",
    34  			errorType:    execution.EfficacyThreshold,
    35  			wantExitMsg:  "below efficacy-threshold",
    36  			wantExitCode: 10,
    37  		},
    38  		{
    39  			name:         "coverage-threshold",
    40  			errorType:    execution.MutantCoverageThreshold,
    41  			wantExitMsg:  "below mutant coverage-threshold",
    42  			wantExitCode: 11,
    43  		},
    44  	}
    45  	for _, tc := range testCases {
    46  		tc := tc
    47  		t.Run(tc.name, func(t *testing.T) {
    48  			err := execution.NewExitErr(tc.errorType)
    49  
    50  			exitCode := err.ExitCode()
    51  			exitMessage := err.Error()
    52  
    53  			if exitCode != tc.wantExitCode {
    54  				t.Errorf("want %d, got %d", tc.wantExitCode, exitCode)
    55  			}
    56  			if exitMessage != tc.wantExitMsg {
    57  				t.Errorf("want %q, got %q", tc.wantExitMsg, exitMessage)
    58  			}
    59  		})
    60  	}
    61  }