• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nats-server / 18183589534
82%

Build:
DEFAULT BRANCH: main
Ran 02 Oct 2025 05:47AM UTC
Jobs 1
Files 60
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

01 Oct 2025 03:37PM UTC coverage: 86.025% (-0.03%) from 86.059%
18183589534

push

github

web-flow
feat: add NewServerFromConfig function for embedded server config processing (#7364)

# Add NewServerFromConfig function for embedded server config processing

## Overview

Resolves #7092

This PR introduces a new `NewServerFromConfig()` function that
automatically processes configuration files for embedded NATS servers.

## Problem

When using NATS embedded in Go applications, developers (such as me)
often pass the `ConfigFile` field in the `Options` struct, but
`NewServer(opts *Options)` doesn't automatically process this
configuration file. This leads to confusion and requires additional
manual steps to load the configuration.

## Solution

### Approach Comparison

In pr #7333, a solution was proposed to directly modify `NewServer()`:

```go
func NewServer(opts *Options) (*Server, error) {
    if opts.ConfigFile != _EMPTY_ && opts.configDigest == "" {
        if err := opts.ProcessConfigFile(opts.ConfigFile); err != nil {
            return nil, err
        }
    }
    // ...original code
}
```

However, directly modifying `NewServer()` might raise concerns about
backward compatibility. Therefore, this PR introduces a dedicated
`NewServerFromConfig()` function specifically to handle the `ConfigFile`
field of `*Options`.

### Implementation

This PR adds:

```go
func NewServerFromConfig(opts *Options) (*Server, error) {
    if opts.ConfigFile != _EMPTY_ && opts.configDigest == "" {
        if err := opts.ProcessConfigFile(opts.ConfigFile); err != nil {
            return nil, err
        }
    }
    return NewServer(opts)
}
```

## Testing

Added comprehensive test coverage:

- **`TestNewServerFromConfigFunctionality`**: Tests basic functionality
and error handling scenarios
- **`TestNewServerFromConfigVsLoadConfig`**: Validates equivalence with
traditional `LoadConfig()` approach using deep equality checks

## Acknowledgments

Thanks to @ripienaar for the suggestion to create a separate function
instead of modifying `NewServer()` directly.

## Sign... (continued)

74392 of 86477 relevant lines covered (86.03%)

352743.25 hits per line

Coverage Regressions

Lines Coverage ∆ File
434
84.38
0.64% src/github.com/nats-io/nats-server/server/filestore.go
426
72.8
-0.56% src/github.com/nats-io/nats-server/server/jetstream_api.go
156
94.41
0.01% src/github.com/nats-io/nats-server/server/server.go
54
81.9
-0.45% src/github.com/nats-io/nats-server/server/jetstream_cluster.go
25
86.37
-0.56% src/github.com/nats-io/nats-server/server/raft.go
20
88.22
-0.22% src/github.com/nats-io/nats-server/server/consumer.go
16
86.24
0.47% src/github.com/nats-io/nats-server/server/memstore.go
14
88.99
-0.35% src/github.com/nats-io/nats-server/server/mqtt.go
7
93.59
-0.28% src/github.com/nats-io/nats-server/server/route.go
6
94.3
-0.24% src/github.com/nats-io/nats-server/server/gateway.go
4
55.91
-0.27% src/github.com/nats-io/nats-server/server/jetstream_errors_generated.go
4
95.73
-0.37% src/github.com/nats-io/nats-server/server/websocket.go
3
95.12
0.0% src/github.com/nats-io/nats-server/server/client.go
2
98.52
-1.48% src/github.com/nats-io/nats-server/server/jetstream_versioning.go
2
86.11
0.07% src/github.com/nats-io/nats-server/server/stream.go
Jobs
ID Job ID Ran Files Coverage
1 18183589534.1 02 Oct 2025 05:47AM UTC 60
86.03
GitHub Action Run
Source Files on build 18183589534
  • Tree
  • List 60
  • Changed 20
  • Source Changed 3
  • Coverage Changed 20
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • Github Actions Build #18183589534
  • d2e3de99 on github
  • Prev Build on main (#18151645615)
  • Next Build on main (#18213110854)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc