github.com/getgauge/gauge@v1.6.9/config/configuration_test.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package config
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  )
    13  
    14  func stubGetFromConfig(propertyName string) string {
    15  	return ""
    16  }
    17  
    18  func stub2GetFromConfig(propertyName string) string {
    19  	return "10000"
    20  }
    21  
    22  func stub3GetFromConfig(propertyName string) string {
    23  	return "false"
    24  }
    25  
    26  func stub4GetFromConfig(propertyName string) string {
    27  	return "true	"
    28  }
    29  
    30  func TestRunnerRequestTimeout(t *testing.T) {
    31  	getFromConfig = stubGetFromConfig
    32  	expected := defaultRunnerRequestTimeout
    33  	got := RunnerRequestTimeout()
    34  	if got != expected {
    35  		t.Errorf("Expected RunnerRequestTimeout == defaultRunnerRequestTimeout(%s), got %s", expected, got)
    36  	}
    37  
    38  	getFromConfig = stub2GetFromConfig
    39  	got1 := RunnerRequestTimeout().Seconds()
    40  	expected1 := float64(10)
    41  	if got1 != expected1 {
    42  		t.Errorf("Expected RunnerRequestTimeout == defaultRunnerRequestTimeout(%f), got %f", expected1, got1)
    43  	}
    44  
    45  	os.Setenv(runnerRequestTimeout, "1000")
    46  	got1 = RunnerRequestTimeout().Seconds()
    47  	expected1 = float64(1)
    48  	if got != expected {
    49  		t.Errorf("Expected RunnerRequestTimeout == defaultRunnerRequestTimeout(%f), got %f", expected1, got1)
    50  	}
    51  }
    52  
    53  func TestAllowUpdates(t *testing.T) {
    54  	getFromConfig = stubGetFromConfig
    55  	if !CheckUpdates() {
    56  		t.Error("Expected CheckUpdates=true, got false")
    57  	}
    58  
    59  	getFromConfig = stub2GetFromConfig
    60  	if !CheckUpdates() {
    61  		t.Error("Expected CheckUpdates=true, got false")
    62  	}
    63  
    64  	getFromConfig = stub3GetFromConfig
    65  	if CheckUpdates() {
    66  		t.Error("Expected CheckUpdates=true, got true")
    67  	}
    68  
    69  	getFromConfig = stub4GetFromConfig
    70  	if !CheckUpdates() {
    71  		t.Error("Expected CheckUpdates=true, got false")
    72  	}
    73  }