github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/common/hugo/hugo_test.go (about) 1 // Copyright 2018 The Hugo Authors. All rights reserved. 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 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package hugo 15 16 import ( 17 "fmt" 18 "testing" 19 20 qt "github.com/frankban/quicktest" 21 ) 22 23 func TestHugoInfo(t *testing.T) { 24 c := qt.New(t) 25 26 conf := testConfig{environment: "production", workingDir: "/mywork", running: false} 27 hugoInfo := NewInfo(conf, nil) 28 29 c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version()) 30 c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version())) 31 c.Assert(hugoInfo.WorkingDir(), qt.Equals, "/mywork") 32 33 bi := getBuildInfo() 34 if bi != nil { 35 c.Assert(hugoInfo.CommitHash, qt.Equals, bi.Revision) 36 c.Assert(hugoInfo.BuildDate, qt.Equals, bi.RevisionTime) 37 c.Assert(hugoInfo.GoVersion, qt.Equals, bi.GoVersion) 38 } 39 c.Assert(hugoInfo.Environment, qt.Equals, "production") 40 c.Assert(string(hugoInfo.Generator()), qt.Contains, fmt.Sprintf("Hugo %s", hugoInfo.Version())) 41 c.Assert(hugoInfo.IsDevelopment(), qt.Equals, false) 42 c.Assert(hugoInfo.IsProduction(), qt.Equals, true) 43 c.Assert(hugoInfo.IsExtended(), qt.Equals, IsExtended) 44 c.Assert(hugoInfo.IsServer(), qt.Equals, false) 45 46 devHugoInfo := NewInfo(testConfig{environment: "development", running: true}, nil) 47 c.Assert(devHugoInfo.IsDevelopment(), qt.Equals, true) 48 c.Assert(devHugoInfo.IsProduction(), qt.Equals, false) 49 c.Assert(devHugoInfo.IsServer(), qt.Equals, true) 50 } 51 52 type testConfig struct { 53 environment string 54 running bool 55 workingDir string 56 } 57 58 func (c testConfig) Environment() string { 59 return c.environment 60 } 61 62 func (c testConfig) Running() bool { 63 return c.running 64 } 65 66 func (c testConfig) WorkingDir() string { 67 return c.workingDir 68 }